<template>
  <div class="app-container">
    <div class="app-container__section">
      <PlusSearch :columns="columns" v-bind="searchBinds"></PlusSearch>
    </div>
    <div class="app-container__section">
      <PlusTable v-bind="tableBinds"  :columns="columns">
        <template #title>
          <table-title />
        </template>
        <template #toolbar>
          <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['message:notice:add']">新增</el-button>
          <el-button  type="success"  plain  icon="Edit"  :disabled="gSelection.length !== 1"  @click="handleUpdate(gSelection[0])"  v-hasPermi="['message:notice:edit']" >
            修改
          </el-button>
          <el-button type="danger" plain icon="Delete" :disabled="gSelection.length === 0" @click="handleDelete(gSelection)" v-hasPermi="['message:notice:remove']" >
            删除
          </el-button>
          <ClockTimer :task="gGetList" />
          <SearchAreaControl v-model="gShowSearchForm" />
        </template>
        <template #plus-cell-noticeType="scope">
          <dict-tag :options="dictData.sys_notice_type" :value="scope.row.noticeType" />
        </template>
        <template #plus-cell-status="scope">
          <dict-tag :options="dictData.sys_notice_status" :value="scope.row.status" />
        </template>
        <!-- 操作列 -->
        <template #plus-cell-action="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['message:notice:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['message:notice:remove']">删除</el-button>
        </template>
      </PlusTable>
    </div>

    <!-- 添加或修改公告对话框 -->
    <addForm ref="addFormRef" @refreshList="gGetList" />

  </div>
</template>

<script setup >
import { useCommonConfig,useColumnsDict} from './hook.js'
import { useDelHook, useListHook } from '@/hooks/crud/index.js'
import { useListConfigHook } from '@/hooks/usePlusConfigHook.js'
import AddForm from './addForm.vue'
defineOptions({
  name: 'Notice'
})
const { proxy,apiFn,primaryKey,moduleName,beforeDelFn } = useCommonConfig()
const { dictData, columns, } = useColumnsDict()

// ====================列表逻辑=========================
const gSearchForm = ref({  })
const { gGetList, gAllExposeOption, } = useListHook({
  listApiFn: apiFn.listApiFn,
  gSearchForm,
  beforeRequest: (reqData) => {
    return reqData
  },
  afterRequest: (resData) => {
    return resData
  }
})
// ====================属性绑定=========================
const { gTableBinds, gSearchBinds, gSelection, gShowSearchForm } = useListConfigHook()
const tableBinds = computed(() => gTableBinds({ ...gAllExposeOption,primaryKey }))
const searchBinds = computed(() => gSearchBinds({ ...gAllExposeOption } ))
// ==================删除逻辑===========================
const { gDelete } = useDelHook({
  delApiFn: apiFn.delApiFn,
  moduleName,
  beforeDelFn: (reqData) => beforeDelFn(reqData),
  afterDelFn: (resData) =>gGetList(),
})
const handleDelete = (data)=>{
  gDelete(data)
}
// ===================新增、修改======================
const addFormRef = ref(null)
// 新增操作
function handleAdd() {
  addFormRef.value.gOpen()
}
// 修改操作
function handleUpdate(row) {
  addFormRef.value.gOpen(row)
}
</script>
